package hyj.qx.websocket.controller;

import hyj.qx.websocket.entity.Content;
import hyj.qx.websocket.enums.ErrorCode;
import hyj.qx.websocket.pojo.ContentQueryDTO;
import hyj.qx.websocket.service.ContentService;
import hyj.qx.websocket.vo.ContentVo;
import hyj.qx.websocket.vo.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "用户消息相关接口")
public class ContentController {

   @Autowired
    private ContentService contentService;

    @PostMapping("getContent")
    @ApiOperation("获取历史信息")
    public JsonResult<List<ContentVo>> getContent(@RequestBody ContentQueryDTO dto) {
        try {
            List<ContentVo> contents = contentService.selectContent(dto.getFromName(), dto.getToName());
            return JsonResult.success(contents);
        } catch (RuntimeException e) {
            e.printStackTrace();
            return JsonResult.Failed(null, ErrorCode.CONTENT_FETCH_FAILED);
        }
    }
}
